package thread;

public class ThreadDead {

	public static void main(String[] args) {
		new TestThread().start();
		
		while(true) {
			try {
				Thread.sleep(10*1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}


class TestThread extends Thread{
	public TestThread() {
		super("TestThread");
		setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				System.out.println("UncaughtExceptionHandler");
				e.printStackTrace();
			}
		});
	}
	
	@Override
	public void run() {
		while(true) {
			System.out.println("TestThread start");
//			try {
//				Thread.sleep(10*1000);
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
			generateException();
			System.out.println("TestThread end");
		}
	}
	
	@SuppressWarnings("null")
	private void generateException() {
		String str = null;
		str.length();
	}
	
	@Override
	public void destroy() {
		System.out.println("destroy");
	}
	
	
}
